function pushCasinoEvent(e){window.dataLayer=window.dataLayer||[],window.dataLayer.push(e)}function getElapsedPlayTimeHellocasino(){return document.cookie.split("; ").find((e=>e.startsWith("Hellocasino_PLAY_PAGE_ELAPSED_TIME_COOKIE=")))?.split("=")[1]||""}function trackLoginEvent(){let e;const t={get:function(){return"true"===localStorage.getItem("isLoggedIn")},set:function(e){localStorage.setItem("isLoggedIn",e)},sync:function(){const e=document.getElementById("logged_in_header_balance"),t=this.get();return null===localStorage.getItem("isLoggedIn")?(this.set(!!e),e||localStorage.removeItem("loginEventSent"),!!e):!t&&e?(this.set(!0),!0):t&&!e?(this.set(!1),localStorage.removeItem("loginEventSent"),!1):t}};function n(){"true"!==localStorage.getItem("loginEventSent")&&(window.dataLayer=window.dataLayer||[],window.dataLayer.push({event:"login_success",event_category:"account",event_action:"login",event_label:"success"}),localStorage.setItem("loginEventSent","true"),"function"==typeof window.initializeDepositTracking&&window.initializeDepositTracking())}function a(){document.getElementById("logged_in_header_balance")&&!t.get()&&(t.set(!0),n())}function o(t,n){t.hasAttribute("data-login-listener")||(t.setAttribute("data-login-listener","true"),t.addEventListener("click",(function(){clearTimeout(e),e=setTimeout(a,1e4)})))}function i(e){e.hasAttribute("data-logout-listener")||(e.setAttribute("data-logout-listener","true"),e.addEventListener("click",(function(){t.set(!1),localStorage.removeItem("loginEventSent"),window.dataLayer=window.dataLayer||[],window.dataLayer.push({event:"logout_success",event_category:"account",event_action:"logout",event_label:"success",user_id:""})})))}t.sync()&&t.get()&&n(),function(){["loginsubmit"].forEach((e=>{const t=document.getElementById(e);t&&o(t)}));const e=document.getElementById("logOutUserBtn");e&&i(e)}();new MutationObserver((function(e){e.forEach((function(e){e.addedNodes&&e.addedNodes.length>0&&e.addedNodes.forEach((e=>{e.nodeType===Node.ELEMENT_NODE&&("loginsubmit"===e.id?o(e,e.id):"logOutUserBtn"===e.id?i(e):"logged_in_header_balance"===e.id&&a(),["loginsubmit","logOutUserBtn","logged_in_header_balance"].forEach((t=>{const n=e.querySelector(`#${t}`);n&&("logOutUserBtn"===t?i(n):"logged_in_header_balance"===t?a():o(n))})))}))}));!document.getElementById("logged_in_header_balance")&&t.get()&&(t.set(!1),localStorage.removeItem("loginEventSent"))})).observe(document.body,{childList:!0,subtree:!0})}function trackSessionStart(){const e=(new Date).getTime(),t=parseInt(localStorage.getItem("lastPageTimestamp"));(!t||e-(t||0)>36e5)&&(window.dataLayer=window.dataLayer||[],window.dataLayer.push({event:"session_start",event_category:"user",event_action:"session",event_label:"start"})),localStorage.setItem("lastPageTimestamp",e.toString())}function initializeCasinoTrackingOnClick(){document.addEventListener("click",(function(e){const t=e.target,n=t.getAttribute("data-category")||t.parentElement.getAttribute("data-category");n&&pushCasinoEvent({event:"casino_lobby_nav",event_category:"lobby",event_action:"navigation",event_label:n});const a=t.getAttribute("data-observer")||t.closest("[data-observer]");if(a){const e=a.querySelector("[data-code]")?.getAttribute("data-code");if(e){pushCasinoEvent({event:"game_open",event_category:"lobby",event_action:"game_open",event_label:e}),localStorage.setItem("lastGameStarted",e);const t=getElapsedPlayTimeHellocasino();localStorage.setItem("lastGameTimePlayedBeforeGameStart",t||"0")}}"close-overlay"===t.id&&t.closest("#games-search-panel")&&pushCasinoEvent({event:"search_complete",event_category:"lobby",event_action:"search",event_label:"complete",search_term:"",next_action:"nav-cancel"})}))}function initializeSearchTracking(){let e=!1;new MutationObserver((t=>{const n=document.getElementById("games-search-panel"),a=document.querySelector(".search-input-box");n&&"block"===n.style.display&&a&&!e&&(pushCasinoEvent({event:"search_start",event_category:"lobby",event_action:"search",event_label:"start"}),e=!0)})).observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["style","class"]})}function attachSearchListener(e){let t;const n=e=>{clearTimeout(t),t=setTimeout((()=>{pushCasinoEvent({event:"search_complete",event_category:"lobby",event_action:"search",event_label:"complete",search_term:e.target.value,next_action:""})}),300)};e.removeEventListener("input",n),e.addEventListener("input",n)}function checkIfGamePlayedAndFinished(){const e=localStorage.getItem("lastGameStarted");let t=localStorage.getItem("lastGameTimePlayedBeforeGameStart");const n=getElapsedPlayTimeHellocasino();e&&t&&n&&pushCasinoEvent({event:"game_close",event_category:"lobby",event_action:"game_close",event_label:e,session_duration:(Number(n)-Number(t))/1e3})}document.addEventListener("DOMContentLoaded",(function(){trackSessionStart(),trackLoginEvent(),initializeCasinoTrackingOnClick(),initializeSearchTracking(),checkIfGamePlayedAndFinished()}));